Topic: Strings Part 2 Points: 25
Goals
- Learn
proper usages of constant parameters.
- Learn
proper usages of constant functions.
- Learn
proper usages of constant return values.
- Review
use of pointers
- Review
dynamic memory
- Make
good use of encapsulation and information hiding
Instructions
- Start
with your files from the previous
string assignment (or files given to you)
- Make
all paramters const
that should not be changed.
- Make
all member functions const that should not
change member variables.
- Make
all return values const that point or reference
a member variable.
- Be
sure your header file can be included twice. Use: #ifndef STRING_H #define STRING_H class
definition #endif
- Be
sure you have no duplicate code. (Use the functions you have written.)
- Make
all functions "this safe".
- Implement
the functions described below.
- Be
sure to check for NULL pointers in every possible scenario.
Functions to Add
- subString - returns a String by value. It should take a starting
index and a length. If the starting index is < 0 start a 0. If
the starting index is > the length of the string return an empty
string. If the length goes past the end of the string, just stop at
the end.
- equals
- return true if the two values are equal. false
otherwise. It should take a String, char*, char or int.
- at
- returns a char at the given index. It should take an integer as a
parameter. If there is not a character at the given index return
'\0'.
- toUpper - should change all of the characters in the string to
upper case.
- toLower - should change all of the characters in the string to
lower case.
- trimStart - removes all of the white-space from the beginning of
the String.
- trimEnd - removes all of the white-space from the end of the
String.
- trim
- removes all of the white-space from the beginning and end of the String.
- replace
- should take two parameters. Search for all occurrences of the first
parameter and replace it with the second parameter. This function can
be called in 16 ways. replace(String, String) replace(String,
char*) replace(String, int)
replace(String, char) replace(char*, String) replace(char*,
char*) replace(char*, int)
replace(char*, char) replace(int, String)
replace(int, char*) replace(int, int) replace(int, char) replace(char, String)
replace(char, char*) replace(char, int)
replace(char, char) Be sure not to replace parts of the String
that you just added
Hints
You should only have to write one replace function. See the Conversion
Constructor Example
Sorry to tell you now but this was true for all of the functions you have
written.